//============================================================================
// Name        : ksUtility.cpp
// Author      : wangchao
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <cstddef>
#include <vector>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <assert.h>

#include "ks/ksDefines.h"
#include "ks/ksProperty.h"
#include "ks/writer/ksEncode.h"
#include "ks/reader/ksDecode.h"

using namespace std;

int main(int args, char** argv)
{
    bool showUsage = false;

    string method;
    string input;
    vector<string> inputs;
    string output;
    vector<string> outputs;
    if (args < 6)
    {
        showUsage = true;
    }
    else
    {
        method = argv[1];
        if (method == "-e" || method == "-d")
        {
            input = argv[2];
            if (input == "-i")
            {
                bool flagInput = true;
                for (int index = 3; index < args; index++)
                {
                    string item = string(argv[index]);
                    if (item != "-o")
                    {
                        if (flagInput)
                            inputs.push_back(item);
                        else
                            outputs.push_back(item);
                    }
                    else
                    {
                        output = item;
                        flagInput = false;
                    }
                }

                if (output != "-o" || inputs.size() == 0 || outputs.size() == 0)
                {
                    showUsage = true;
                }
                else
                {
                    if (method == "-e")
                    {
                        ksEncode(inputs[0].c_str(), outputs[0].c_str(), true);
                        ksDecode(outputs[0].c_str(), "d:\\novelTest\\novel1\\out\\");
                    }
                    else if (method == "-d")
                    {
                        ksDecode(inputs[0].c_str(), outputs[0].c_str());
                    }
                    else
                    {

                    }
                }
            }
            else
            {
                showUsage = true;
            }
        }
        else
        {
            showUsage = true;
        }
    }
    if (showUsage)
    {
        cout << "Usage:ksUtility -e|-d -i input -o output" << endl;
        cout << " e:encode a directory to a ks file" << endl;
        cout << " d:decode a ks file to a directory" << endl;
    }
    return 0;
}

